﻿#ifndef C3FDRENDERWINDOW_H
#define C3FDRENDERWINDOW_H

#include "mainWidgetsAPI.h"
#include <QWidget>
#include <QList>
#include <QVector>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkTextWidget.h>
#include <QGridLayout>
#include <QFile>
#include <QHash>
#include "C3fdRenderWidget.h"
#include "C3fdChartWidget.h"


class TopoDS_Edge;
class TopoDS_Shape;

namespace Ui
{
	class C3fdRenderWindow;
}

namespace GUI
{
	class MainWindow;
}

namespace MainWidget
{
	enum class RenderType : int {
		Undefined,
		GeomRender,
		MeshRender,
		PostRender,
		PerformRender,
		MonitorRender,
	};

	class MAINWIDGETSAPI C3fdRenderWindow : public QWidget
	{
		Q_OBJECT
	public:
		explicit C3fdRenderWindow(GUI::MainWindow *mw);
		~C3fdRenderWindow();

		void renderC3fdGeom(const QStringList &files, bool showHubAndShroud);
		void renderC3fdMesh(QStringList files);
		void renderC3fdPerformCurve(QList<QList<double>>, QList<QList<double>>);
		void renderC3fdMonitorCurve(QString file);
		void renderC3fdPostData(QStringList files, QStringList types);

		void setView(QString view);

		bool save();

	signals:
		void closed();
		void updateRowTreeSig();

	public slots:
		void postSaveImageSlot(const QString &, QString, int);
		void renderC3fdCacheSlot();
		void finishRenderGeomTurboFileSlot();
		void updateGeomDisplayStatusSlot(QString, bool);
		void changeControlTabSlot(QString);

	private:
		void renderC3fdGeomCache();

		bool clearLayout(bool delChild = false);
		bool initGeomRenderWidget(bool reset = true);
		bool initMeshRenderWidget(bool reset = true);
		bool initMonitorChartWidget(bool reset = true);
		bool initPerformChartWidget(bool reset = true);
		bool initPostRendererWidget(bool reset = true);
		bool hideAllWidget();
		bool renderPostFile(const QStringList &files, const QStringList &types);

		void renderGeomTurboFile(vtkSmartPointer<vtkRenderer> renderer, const QStringList &files, bool showHubAndShroud);

		QString translate(QString) const;

	private:
		GUI::MainWindow *m_MainWindow = nullptr;
		Ui::C3fdRenderWindow *m_Ui = nullptr;
		QGridLayout *m_Layout = nullptr;


		bool m_ReadFromCache = false;

		C3fdRenderWidget* m_GeomRenderWidget = nullptr;
		QList<C3fdRenderWidget*> m_MeshRenderWidgets = {};
		QList<QPair<QString, QWidget *>> m_PostRenderWidgets = {};
		QList<C3fdChartWidget*> m_PerformCurveWidgets = {};
		C3fdChartWidget *m_MonitorCurveWidget = nullptr;

		RenderType m_CurrentRenderType = RenderType::Undefined;
	};
}

#endif // C3FDRENDERWINDOW_H
